package com.jinyin.maven.hibernate2_maven.Demo;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

import com.jinyin.maven.hibernate2_maven.po.Datp;
import com.jinyin.maven.hibernate2_maven.po.Demp;

public class Demo2 {
       public static void main(String[] args) {
    	   //新版本创建工厂
    	   StandardServiceRegistry regstiy=new StandardServiceRegistryBuilder()
    			   .configure()//configuers settings from hibernate.cfg.xml
    			   .build();
    	   //创建会话工厂
    	   SessionFactory factory=new MetadataSources(regstiy).buildMetadata().buildSessionFactory();
    	   //创建会话对象
    	   Session session=factory.openSession();
    	   //创建事物
    	   session.beginTransaction();
    	   //创建部门
    	   Datp d=new Datp();
    	   d.setDatpName("教务处2");
    	   
    	   //创建员工
    	   Demp de=new Demp();
    	   de.setDatpId(d);
    	   de.setDempName("赵六2");
    	   de.setDempSex(1);
    	   de.setDempAge(30);
    	   session.save(de);
    	   session.getTransaction();//提交事物
    	   session.close();
    	   
	}
}
